package com.exam.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.exam.mapper.AdminMapper;
import com.exam.pojo.Admin;
import com.exam.pojo.Login;
import com.exam.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin getAdmin(Login login) {
        Admin admin = new Admin();
        byte[] psd = login.getPassword().getBytes();
        String psdMd = DigestUtils.md5DigestAsHex(psd);
        System.out.println(psdMd);
        admin.setAdminId(login.getUsername()).setPwd(psdMd);
        QueryWrapper<Admin> queryWrapper = new QueryWrapper<>(admin);
        Admin admin1 = adminMapper.selectOne(queryWrapper);
        return admin1;
    }
//    public void test(Login login){
//        Admin admin=new Admin();
//        byte[] psd = login.getPassword().getBytes();
//        String s = DigestUtils.md5DigestAsHex(psd);
//        admin.setAdminId(login.getUsername());
//        admin.setPwd(s);
//
//    }
}
